require 'rubygems'
require 'simple-rss'
require 'appengine-apis/urlfetch'

class FeedMaker

  FEED_URL = "http://d.hatena.ne.jp/fuzzhead/rss2"

  #前回日時(yyyyMMddhh)
  @@previous_dt = nil
  
  #キャッシュ
  @@feed_cache = nil

  def self.get_feed(feed_url = FEED_URL)
    now = Time.now.strftime("%Y%m%d%H")
    if now != @@previous_dt then
      @@feed_cache = fetch_feed(feed_url)
    end
    @@previous_dt = now
    return @@feed_cache
  end
  
  private 
  
  def self.fetch_feed(feed_url)
    rawfeed = AppEngine::URLFetch.fetch(feed_url)
    return SimpleRSS.parse(rawfeed.body)
  end
end
  




